package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.pudao.PuDaoFederalLearningRiskModelData;
import com.ucredit.babel.common.model.third.pudao.PuDaoFederalLearningRiskModel;
import com.ucredit.babel.common.model.third.pudao.PuDaoFederalLearningRiskModelRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 联邦学习
 *
 * @author guoqiang
 */
public class PuDaoFederalLearningRiskModelParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 联洋-黑卡定制分B
     *
     * @param model
     * @throws InterruptedException
     * @throws IOException
     */
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        PuDaoFederalLearningRiskModelRecord obj = (PuDaoFederalLearningRiskModelRecord) model;
        PuDaoFederalLearningRiskModelData scoreData = obj.getData();
        PuDaoFederalLearningRiskModel data = scoreData.getData();
        StringBuilder sb = getBaseInfo(obj, successful);
        sb.append(formatValue(data.getScore())).append(CRT001);
        sb.append(formatValue(data.getTags())).append(CRT001);
        sb.append(formatValue(data.getExtra())).append(CRT001);
        sb.append(formatValue(data.getFederatedScore())).append(CRT001);
        sb.append(formatValue(data.getFederatedScores())).append(CRT001);
        sb.append(formatValue(data.getFederatedTrees())).append(CRT001);
        sb.append(formatValue(data.getExtensionOut())).append(CRT001);
        sb.append(formatValue(scoreData.getCode())).append(CRT001);
        sb.append(formatValue(scoreData.getMsg())).append(CRT001);
        sb.append(formatValue(scoreData.getSeqNo())).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_pudaofederallearning_risk_model_inc";
    }

    @Override
    public String getType() {
        return RecordType.PD_FEDERAL_LEARNING_RISK_MODEL_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "联邦学习";
    }

}
